package com.chenyun.common.vo;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.chenyun.common.enums.LoginDeviceTypeEnum;
import com.chenyun.common.enums.LoginUserTypeEnum;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

/**
 * @descriptions: 登录用户信息
 * @author: Lonni
 * @date: 2021/1/7 16:06
 * @version: 1.0
 */
@Builder
@Data
public class SessionUser implements Serializable {

    private static final long serialVersionUID = 3862561158892022004L;
    private String userId;
    private String userName;
    private String nickName;
    private String phone;
    /**
     * 店铺id
     */
    private String shopId;
    /**
     * 店铺名称
     */
    private String shopName;
    private String deptId;
    private String deptName;
    private String unionId;
    private String openId;
    /**
     * 租户id
     */
    private String clientId;




    public SessionUser(){}

    public SessionUser(String userId, String userName, String nickName, String phone, String shopId, String shopName, String deptId, String deptName, String unionId, String openId, String clientId, String password, Set<String> menuPermission, Set<String> rolePermission, LoginUserTypeEnum userType, LoginDeviceTypeEnum deviceType) {
        this.userId = userId;
        this.userName = userName;
        this.nickName = nickName;
        this.phone = phone;
        this.shopId = shopId;
        this.shopName = shopName;
        this.deptId = deptId;
        this.deptName = deptName;
        this.unionId = unionId;
        this.openId = openId;
        this.clientId = clientId;
        this.password = password;
        this.menuPermission = menuPermission;
        this.rolePermission = rolePermission;
        this.userType = userType;
        this.deviceType = deviceType;
    }

    /**
     * 密码
     */
    private String password;
    private Set<String> menuPermission;
    private Set<String> rolePermission;
    /**
     * 用户类型
     */
    private LoginUserTypeEnum userType;
    /**
     * 设备类型
     */
    private LoginDeviceTypeEnum deviceType;


    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getShopId() {
        return shopId;
    }

    public void setShopId(String shopId) {
        this.shopId = shopId;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public String getDeptId() {
        return deptId;
    }

    public void setDeptId(String deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getUnionId() {
        return unionId;
    }

    public void setUnionId(String unionId) {
        this.unionId = unionId;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Set<String> getMenuPermission() {
        return menuPermission;
    }

    public void setMenuPermission(Set<String> menuPermission) {
        this.menuPermission = menuPermission;
    }

    public Set<String> getRolePermission() {
        return rolePermission;
    }

    public void setRolePermission(Set<String> rolePermission) {
        this.rolePermission = rolePermission;
    }

    public LoginUserTypeEnum getUserType() {
        return userType;
    }

    public void setUserType(LoginUserTypeEnum userType) {
        this.userType = userType;
    }

    public LoginDeviceTypeEnum getDeviceType() {
        return deviceType;
    }

    public void setDeviceType(LoginDeviceTypeEnum deviceType) {
        this.deviceType = deviceType;
    }




    public SessionUser builderSysUserDefault(){
        SessionUser user=new SessionUser();
        user.setUserId("system");
        return user;
    }

    /**
     * 测试用
     * @return
     */
    @Deprecated
    public SessionUser defaultSessionUser(){
       return SessionUser.builder()
               .phone("13419535285")
               .openId("")
               .deptName("测试部门")
               .deptId("123")
               .nickName("lonni")
               .userName("lonni")
               .userId("1001")
               .userType(LoginUserTypeEnum.PLAT_FORM_ADMIN)
               .deviceType(LoginDeviceTypeEnum.PC)
               .shopId("")
               .shopName("")
               .password(DigestUtil.sha1Hex("123456"))
               .menuPermission(new HashSet<String>(){{
                   add("sys:user:info");
                   add("sys:user:info1");
                   add("sys:user:info2");
                   add("sys:user:info3");
               }})
               .rolePermission(new HashSet<String>(){{
                   add("admin");
                   add("user1");
                   add("user2");
                   add("user3");
               }})
               .build();
    }

    @Override
    public String toString() {
        return "SessionUser{" +
                "userId='" + userId + '\'' +
                ", userName='" + userName + '\'' +
                ", nickName='" + nickName + '\'' +
                ", phone='" + phone + '\'' +
                ", shopId='" + shopId + '\'' +
                ", shopName='" + shopName + '\'' +
                ", deptId='" + deptId + '\'' +
                ", deptName='" + deptName + '\'' +
                ", unionId='" + unionId + '\'' +
                ", openId='" + openId + '\'' +
                ", clientId='" + clientId + '\'' +
                ", password='" + password + '\'' +
                ", menuPermission=" + menuPermission +
                ", rolePermission=" + rolePermission +
                ", userType=" + userType +
                ", deviceType=" + deviceType +
                '}';
    }
}
